home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Belgian Amiga Club - ADF Collection
/
BS1 part 26.zip
/
BS1 part 26
/
C for beginners.adf
/
programs
/
array.asm
< prev
next >
Wrap
Assembly Source File
|
1978-01-17
|
3KB
|
204 lines
;:ts=8
;/* array.c 13 */
;
;#define FALSE 0
;#define TRUE 1
;#define MAXENTRY 20
;
;long total(); /* Declaration of the function */
;
;void main()
;{
public _main
_main:
link a5,#.2
movem.l .3,-(sp)
; int i, number, end = FALSE;
clr.w -6(a5)
; long sum, data[MAXENTRY];
;
; for(i = 0; i <MAXENTRY && !end; i++)
clr.w -2(a5)
bra .7
.6
; {
; printf("Enter %d. value: ", i+1);
move.w -2(a5),d0
add.w #1,d0
move.w d0,-(sp)
pea .1+0
jsr _printf
add.w #6,sp
; scanf("%6ld", &data[i]); /* 6 digits limit */
move.w -2(a5),d0
ext.l d0
asl.l #2,d0
lea -90(a5),a0
add.l a0,d0
move.l d0,-(sp)
pea .1+18
jsr _scanf
add.w #8,sp
; if(!data[i])
; end = TRUE;
move.w -2(a5),d0
ext.l d0
asl.l #2,d0
lea -90(a5),a0
tst.l (a0,d0.l)
bne .8
move.w #1,-6(a5)
; }
.8
.4
add.w #1,-2(a5)
.7
cmp.w #20,-2(a5)
bge .9
tst.w -6(a5)
beq .6
.9
.5
;
;number = i - end; /* If last entry 0, than one less */
move.w -2(a5),d0
sub.w -6(a5),d0
move.w d0,-4(a5)
;sum = total(data, number);
move.w -4(a5),-(sp)
pea -90(a5)
jsr _total
add.w #6,sp
move.l d0,-10(a5)
;printf("The Sum of all %d values is %ld\n", number, sum);
move.l -10(a5),-(sp)
move.w -4(a5),-(sp)
pea .1+23
jsr _printf
lea 10(sp),sp
; printf("Deviation from Average %.9lf:\n", (double) sum / numb
;er);
move.l -10(a5),d0
jsr .Fflt#
move.w -4(a5),d1
ext.l d1
move.l d0,-(sp)
move.l d1,d0
jsr .Fflt#
move.l d0,d1
move.l (sp)+,d0
jsr .Fdiv#
clr.l -(sp)
move.l d0,-(sp)
pea .1+56
jsr _printf
lea 12(sp),sp
;for(i=0; data[i] > 0; i++)
clr.w -2(a5)
bra .13
.12
; printf("Value %d: %5.9lf%%\n", i+1, data[i] * 100.0 / ( (doub
;le) sum / number ) - 100.0);
move.w -2(a5),d0
ext.l d0
asl.l #2,d0
lea -90(a5),a0
move.l d0,d1
move.l (a0,d1.l),d0
jsr .Fflt#
move.l #$c8000047,d1
jsr .Fmul#
move.l d0,-(sp)
move.l -10(a5),d0
jsr .Fflt#
move.w -4(a5),d1
ext.l d1
move.l d0,-(sp)
move.l d1,d0
jsr .Fflt#
move.l d0,d1
move.l (sp)+,d0
jsr .Fdiv#
move.l d0,d1
move.l (sp)+,d0
jsr .Fdiv#
move.l #$c80000c7,d1
jsr .Fadd#
clr.l -(sp)
move.l d0,-(sp)
move.w -2(a5),d0
add.w #1,d0
move.w d0,-(sp)
pea .1+87
jsr _printf
lea 14(sp),sp
.10
add.w #1,-2(a5)
.13
move.w -2(a5),d0
ext.l d0
asl.l #2,d0
lea -90(a5),a0
tst.l (a0,d0.l)
bgt .12
.11
;}
.14
movem.l (sp)+,.3
unlk a5
rts
.2 equ -90
.3 reg
.1
dc.b 69,110,116,101,114,32,37,100,46,32,118,97,108,117,101
dc.b 58,32,0,37,54,108,100,0,84,104,101,32,83,117,109
dc.b 32,111,102,32,97,108,108,32,37,100,32,118,97,108,117
dc.b 101,115,32,105,115,32,37,108,100,10,0,68,101,118,105
dc.b 97,116,105,111,110,32,102,114,111,109,32,65,118,101,114
dc.b 97,103,101,32,37,46,57,108,102,58,10,0,86,97,108
dc.b 117,101,32,37,100,58,32,37,53,46,57,108,102,37,37
dc.b 10,0
ds 0
;
;long total(array, cnt)
;long array[];
public _total
_total:
link a5,#.16
movem.l .17,-(sp)
;int cnt;
;{
; long sum = 0;
clr.l -4(a5)
;
; while(cnt--) /* short and precise */
.18
move.w 12(a5),d0
sub.w #1,12(a5)
tst.w d0
beq .19
; sum += array[cnt];
move.w 12(a5),d0
ext.l d0
asl.l #2,d0
move.l 8(a5),a0
move.l (a0,d0.l),d1
add.l d1,-4(a5)
bra .18
.19
; return sum;
move.l -4(a5),d0
.20
movem.l (sp)+,.17
unlk a5
rts
;}
.16 equ -4
.17 reg
;
public _scanf
public _printf
public .begin
dseg
end